﻿import com.dinmax.flash.central.extension.ExtensionFactory
import com.dinmax.flash.central.extension.state.*
import com.dinmax.flash.utilities.xml.*
import com.dinmax.flash.utilities.date.JavaDateParser

class StateFactory {

	public static function getState(node:XMLNode):State {
		// convierto el timer que me pasa java a un objeto Date de AS
		var stateDate:Date = JavaDateParser.convertDate(Number(XMLUtils.getAttribute(node, "time")));
		
		if(node == undefined)trace("StateFactory.as | nodo indefinido");
		//trace("StateFactory.as | me llega un estado= "+XMLUtils.getAttribute(node, "description"));
		switch (XMLUtils.getAttribute(node, "description")) {
			
			case "offline":
			return new Disabled(stateDate);
			break;
			
			case "online":
			return new Enabled(stateDate);
			break;
			
			case "talking":
			return new Active(stateDate, ExtensionFactory.getExtension(node.childNodes[0].childNodes[0]));
			break;
			
			case "calling":
			//trace("StateFactory.as | todavía no definí el state calling");
			//trace("\n\n---StateFactory.as | stateCalling()\n"+node.childNodes[0].childNodes[0]+"\n\n----");
			return new Calling(stateDate, ExtensionFactory.getExtension(node.childNodes[0].childNodes[0]));
			break;
			
			case "ringing":
			//trace("StateFactory.as | todavía no definí el state ringing");
			return new Ringing(stateDate, ExtensionFactory.getExtension(node.childNodes[0].childNodes[0]));
			break;
			
			default:
			trace("StateFactory.as | 40 | NO RECONOZCO EL ATRIBUTO\nNode Description= "+XMLUtils.getAttribute(node, "description"));
			trace("\nNode= "+node);
			return undefined;
			break;
			
		}; // fin switch
	
	};

}; // fin de clase